package Bean;

import javax.swing.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author 黄忠
 */

@SuppressWarnings("unused")
public class CheckBean {
    public static final int IDENTITYCODE_OLD = 15; // 老身份证15位
    public static final int IDENTITYCODE_NEW = 18; // 新身份证18位
    public static int[] Wi = new int[17];

    public static void alert(String msg){
        int type= JOptionPane.YES_NO_CANCEL_OPTION;
        String title="信息提示";
        JOptionPane.showMessageDialog(null, msg, title, type);
    }
    public static boolean is_numberOrAlpha(String str){
        if (str==null) return false;
        return  str.matches("^[a-z0-9A-Z]+$");
    }
    public static boolean is_chineseOrAlpha(String str){
        if (str==null) return false;
        return  str.matches("^[a-zA-Z\u4e00-\u9fa5]+$");
    }
    public static boolean is_number(String number) {
        if(number==null) return false;
        return number.matches("[+-]?[1-9]+[0-9]*(\\.[0-9]+)?");
    }

    public static boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if( !isNum.matches() ){
            return false;
        }
        return true;
    }

    public static boolean is_alpha(String alpha) {
        if(alpha==null) return false;
        return alpha.matches("[a-zA-Z]+");
    }

    public static boolean is_chinese(String chineseContent) {
        if(chineseContent==null) return false;
        return chineseContent.matches("[\u4e00-\u9fa5]");
    }
    public static boolean isIdentityCode(String code) {
        if (code == null) return false;
        String birthDay = "";
        code = code.trim().toUpperCase();

        if ((code.length() != IDENTITYCODE_OLD)
                && (code.length() != IDENTITYCODE_NEW)) {
            return false;
        }

        Pattern pt = Pattern.compile("(^\\d{15}$)|(\\d{17}(?:\\d|x|X)$)");
        Matcher mt = pt.matcher(code);
        if (!mt.find()) {
            return false;
        }
        return true;
    }
}
